#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = 1010;
int arr[N];
int f[N];
int n, m;
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
	}
	cin >> m;
	sort(arr + 1, arr + 1 + n);
	for (int i = 1; i < n; i++) {
		for (int j = m; j >= arr[i]; j--) {
			f[j] = max(f[j], f[j - arr[i]] + arr[i]);
		}
	}
	cout << f[m] << endl;
	return 0;
}